package com.example.controller;

import com.example.entity.Ebook;
import com.example.req.EbookQueryReq;
import com.example.req.EbookSaveReq;
import com.example.service.EbookService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController()
public class EbookController {

    @Autowired
    EbookService ebookService;

    @GetMapping("/ebookList")
    public Result findEbook(@Valid EbookQueryReq req){
        return Result.success(ebookService.findEbook(req));
    }
    
    @PostMapping("/ebook")
    public Result saveEbook(@RequestBody @Valid EbookSaveReq req) {
        ebookService.saveEbook(req);
        return Result.success();
    }

    @DeleteMapping("/ebook/{id}")
    public Result deleteEbook(@PathVariable("id") Long id){
        ebookService.deleteEbook(id);
        return Result.success();
    }
}
